package com.easy.query.demo.controller;

import com.easy.query.api4j.client.EasyQuery;
import com.easy.query.core.api.pagination.EasyPageResult;
import com.easy.query.demo.domain.DefaultPageResult1;
import com.easy.query.demo.domain.SysUser;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * create time 2023/9/22 22:48
 * 文件说明
 *
 * @author xuejiaming
 */
@RestController
@RequestMapping("/my")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class MyController {

    private final EasyQuery easyQuery;

    @GetMapping("/query")
    public Object query() {
        List<SysUser> list = easyQuery.queryable(SysUser.class)
                .toList();
        return list;
    }
    @GetMapping("/query1")
    public Object query1() {
        EasyPageResult<SysUser> pageResult = easyQuery.queryable(SysUser.class).toPageResult(1, 2);
        DefaultPageResult1<SysUser> page = new DefaultPageResult1<>();
        page.setTotal(pageResult.getTotal());
        page.setData(pageResult.getData());
        return page;
    }
}
